var api = require("../../../api.js"), utils = require("../../../utils.js"), app = getApp(), is_loading = false, is_no_more = false;

Page({
  data: {
    page: 1,
    page_count: 1,
    barginList: [],
    mch_id: 0
  },
  onLoad: function (option) {
    var that = this;
    app.pageOnLoad(this);
    if (option.mch_id) {
      this.setData({mch_id: option.mch_id});
    }
    this.loadData();
  },
  onReady: function () { },
  onShow: function () { },
  onHide: function () { },
  onUnload: function () { },
  onPullDownRefresh: function () { },
  onReachBottom: function () { },
  onShareAppMessage: function () { },
  loadData () {
    var that = this, curPage = that.data.page;
    wx.showLoading({
        title: "加载中"
    });
    var rData = {page: curPage};
    this.data.mch_id && (rData.mch_id = this.data.mch_id);
    app.request({
      url: api.cut.list,
      data: rData,
      success: function (res) {
        if (res.code == 0) {
          that.setData({
            page: curPage + 1,
            page_count: res.data.page_count,
            barginList: res.data.list
          });
        }
      },
      fail: function (err) {
        wx.showToast({
          title: '获取砍价商品列表失败',
          image: "http://runwu100.img.guoxiaoge.cn/icon-warning.png"
        });
      },
      complete: function (d) {
        wx.hideLoading();
      }
    });
  }
});